package com.itheima.d3_collection_test.Exercise;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @ClassName room
 * @Author 16799
 * @Date 2025/8/9 22:02
 * @Version 1.0
 * @Description TODO
 **/
public class room {
    private List<card> allCards = new ArrayList<>();

    public room(){
        String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String[] colors = {"♠", "♥", "♣", "♦"};
        int size = 0;
        for (String number : numbers) {
            size++;
            for (String color : colors) {
                card c = new card(number,color,size);
                allCards.add(c);
            }
        }

        card c1 = new card("","小王",++size);
        card c2 = new card("","大王",++size);

        Collections.addAll(allCards,c1,c2);
        System.out.println("新牌的结果： "+allCards);
    }

    public void start(){
        Collections.shuffle(allCards);
        System.out.println("洗牌的结果： " + allCards);

        List<card> zengjihong = new ArrayList<>();
        List<card> laopo = new ArrayList<>();
        List<card> qiqiqi = new ArrayList<>();

        for (int i = 0; i < allCards.size()-3; i++) {
            card c = allCards.get(i);
            if (i%3==0){
                zengjihong.add(c);
            }else if (i%3==1){
                laopo.add(c);
            } else if (i%3 == 2) {
                qiqiqi.add(c);
            }
        }

        System.out.println("----------------三个人不排序的牌：-----------");
        System.out.println("zengjihong: "+zengjihong);
        System.out.println("laopo: "+laopo);
        System.out.println("qiqiqi: "+qiqiqi);

        System.out.println("====================排序后的结果：===========");

        sortCards(zengjihong);
        sortCards(laopo);
        sortCards(qiqiqi);

        System.out.println("zengjihong: "+zengjihong);
        System.out.println("laopo: "+laopo);
        System.out.println("qiqiqi: "+qiqiqi);

        List<card> lastCard = allCards.subList(allCards.size()-3,allCards.size());
        System.out.println("三种底牌为： "+lastCard);
        zengjihong.addAll(lastCard);
        sortCards(zengjihong);
        System.out.println("zengjihong抢到地主后的牌： "+zengjihong);

    }

    private void sortCards(List<card> cards){

        Collections.sort(cards, new Comparator<card>() {
            @Override
            public int compare(card o1, card o2) {
                return o1.getSize()-o2.getSize();
            }
        });
    }
}
